<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Quiz/classes/PhpFox_ComponentAdminList.class.php, $Author:  $ */



/** List of quizzes (for aprove) in admin area
 * 
 *   
 * @version $Id: PhpFox_ComponentAdminList.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.quiz
 */
class PhpFox_Mod_Quiz_ComponentAdminList extends BaseComponent
{
    function process()
    {
        $oSrvQuiz = &$this->_oModule->getService('Quiz');
        /* @var $oSrvQuiz PhpFox_Mod_Quiz_ServiceQuiz */
        
        $oReq = &App::getRequest();
        /* @var $oReq Request */
        
        $oSrvSec = &App::getModuleService('Account', 'Security');
        /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
        
        switch($oReq->getAction())
        {
            case 'quiz_delete':
                $oSrvQuiz->deleteQuiz($oReq->getInt('quizid'));
                $oUrl = &App::getUrl();
                $oUrl->clearParams('act');
                $oUrl->clearParams('quizid');
                App::forward($oUrl->getUrl(), App::format('Mod_Quiz.quiz_deleted'),
                             'message', App::getPageName(), 'QuizAdminList');
                break;
                
            case 'quiz_approve':
                $oSrvQuiz->approveQuiz($oReq->getInt('quizid'));
                $oUrl = &App::getUrl();
                $oUrl->clearParams('act');
                $oUrl->clearParams('quizid');
                App::forward($oUrl->getUrl(), App::format('Mod_Quiz.quiz_approved'),
                             'message', App::getPageName(), 'QuizAdminList');
                break;                
        }
        
        $iPage = $oReq->get('page', 1);
        $iPageSize = App::getParam('public.pagesize');
        
        $aCond = array(
            'type <> 2', //2 -- hard legacy (used for approved quizzes)
        );
        $sSort = '`id` DESC ';
        list($aQuizzes, $iCnt) = $oSrvQuiz->getQuizList($aCond, $iPage, $iPageSize, $sSort);

        $oPager = App::newObject('Pager', $iCnt, $iPage, $iPageSize);
        
        $oQuestion = $this->_oModule->getItem('Question');
        foreach($aQuizzes as $k=>$v)
        {
            list($aQuizzes[$k]['questions']) = $oQuestion->getList(array('cid = '.$v['id']));
        }
        
        $oTpl = &$this->_oModule->getTemplate();
        $oTpl->assign(array(
            'aQuizzes'    => $aQuizzes,
            //'sUserPicUrl' => App::getParam('user.pic.url'),
            'aPaging'     => $oPager->getInfo(App::getUrl()),
            'bIsAdmin'    => $oSrvSec->isStaff(),
        ));
        return $oTpl->fetch('AdminList.html');
    }
}
?>